import 'package:sinosheets/network/api.dart';
import 'package:sinosheets/utils/language/language_util.dart';

class ResourceApis {
  static CouponIssue couponIssue = CouponIssue();
  static Order order = Order();
  static Search search = Search();
  static Report report = Report();
  //运费估算查询国家 get
  static Future<BaseResponse> queryDataRegionNoPage({String level = "2", String code = ""}) {
    Map parameters = {
      "level": level,
    };
    if (code.isNotEmpty) {
      parameters["code"] = code;
    }
    return HttpClient().request(
      "/resource/region/queryDataRegionNoPage",
      HttpMethod.get,
      parameters: parameters,
      isShowLoading: true,
    );
  }

  //上传文件 /resource/oss/uploadFile POST
  static Future<BaseResponse> uploadFile({required Map data}) {
    return HttpClient().request(
      "/resource/oss/uploadFile",
      HttpMethod.postFormData,
      parameters: data,
      isShowLoading: true,
    );
  }

  //文件上传base64 /resource/oss/uploadBase64 POST
  static Future<BaseResponse> uploadBase64(String base64) {
    return HttpClient().request(
      "/resource/oss/uploadBase64",
      HttpMethod.post,
      parameters: {
        'base64': base64,
      },
      isShowLoading: true,
    );
  }

  //检查app版本  /resource/appVersion/checkAppVersion  GET
  static Future<BaseResponse> checkAppVersion(String version) {
    return HttpClient().request(
      "/resource/appVersion/checkAppVersion",
      HttpMethod.get,
      parameters: {'version': version},
      isShowLoading: true,
    );
  }

  /// 获取rsa公钥  /resource/rsa/publicKey GET
  static Future<BaseResponse> rsaPublicKey() {
    return HttpClient().request(
      "/resource/rsa/publicKey",
      HttpMethod.get,
      isShowLoading: true,
    );
  }

  ///翻译图片接口 /resource/translate/batchTransImg POST
  static Future<BaseResponse> batchTransImg(List imageUrls) {
    return HttpClient().request(
      "/resource/translate/batchTransImg",
      HttpMethod.post,
      parameters: {'sourceLanguage': 'zh', 'targetLanguage': LanguageUtil.getLanguageCode(), 'imageUrls': imageUrls},
      isShowLoading: true,
    );
  }

  ///查询多语言 /resource/lang/getLangResult POST
  static Future<BaseResponse> getLangResult() {
    return HttpClient().request(
      "/resource/lang/getLangResult",
      HttpMethod.post,
      parameters: {
        'locales': ['zh', 'en'],
        'namespace': 'buy_app'
      },
    );
  }

  ///查询系统开关 /resource/dictData/getDictList POST
  static Future<BaseResponse> getAllDictList() {
    return HttpClient().request(
      "/resource/dictData/getDictList",
      HttpMethod.post,
      parameters: {
        'dictType': 'SystemSwitch',
      },
    );
  }

  ///查询单独系统开关 /resource/dictData/getDictList POST
  static Future<BaseResponse> getDictData(String dictLabel) {
    return HttpClient().request(
      "/resource/dictData/getDictList",
      HttpMethod.post,
      parameters: {
        'dictType': 'SystemSwitch',
        'dictLabel': dictLabel,
      },
    );
  }

  ///检查邀请码是否有效 /kol/kol/validateInviteCode get
  static Future<BaseResponse> validateInviteCode(String code) {
    return HttpClient().request(
      "/kol/kol/validateInviteCode",
      HttpMethod.get,
      parameters: {'inviteCode': code},
    );
  }
}

class CouponIssue {
  //用户优惠券列表  /resource/couponIssue/list POST
  Future<BaseResponse> list(Map params, {bool showLoading = true}) {
    return HttpClient().request(
      "/resource/couponIssue/getList",
      HttpMethod.post,
      parameters: params,
      isShowLoading: showLoading,
    );
  }

  //用户兑换优惠券  /resource/couponIssue/exchange POST
  Future<BaseResponse> exchange(String code) {
    return HttpClient().request(
      "/resource/couponIssue/exchange",
      HttpMethod.post,
      parameters: {
        'code': code,
      },
      isShowLoading: true,
    );
  }

  //用户提包可用优惠券列表 /resource/couponIssue/userBagCouponList POST
  Future<BaseResponse> userBagCouponList(double amount, {bool freeProductFlag = false}) {
    return HttpClient().request(
      "/resource/couponIssue/userBagCouponList",
      HttpMethod.post,
      parameters: {'amount': amount, 'freeProductFlag': freeProductFlag},
      isShowLoading: true,
    );
  }
}

class Order {
  //获取提包商品分类信息 /resource/category/getByIdList POST
  Future<BaseResponse> getByIdList(List idList) {
    return HttpClient().request(
      "/resource/category/getByIdList",
      HttpMethod.post,
      parameters: {'idList': idList},
      isShowLoading: true,
    );
  }
}

class Search {
  //获取热门词汇列表 /resource/hotkey/getList POST
  Future<BaseResponse> getHotKeyList() {
    return HttpClient().request(
      "/resource/hotkey/getList",
      HttpMethod.post,
      isShowLoading: false,
    );
  }
}

class Report {
  //举报商品 /resource/report/reportProduct POST
  Future<BaseResponse> reportProduct(Map params) {
    return HttpClient().request("/resource/productReport/report", HttpMethod.post, parameters: params);
  }

  // 用户商品举报列表 /resource/productReport/getList POST
  Future<BaseResponse> getList(Map params) {
    return HttpClient().request("/resource/productReport/getList", HttpMethod.post, parameters: params);
  }
}
